package bysj.dao;

import bysj.domain.File;

import java.sql.*;

public class FileDao {
    private static FileDao fileDao = new FileDao();

    public static FileDao getInstance() {
        return  fileDao;
    }

    public Integer add(File file, Connection conn) throws SQLException {
        String sql="insert into file(fileName,filePath) values(?,?)";
        PreparedStatement ptmt=conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ptmt.setString(1, file.getFileName());
        ptmt.setString(2, file.getFilePath());
        ptmt.executeUpdate();
        ResultSet generatedKeys = ptmt.getGeneratedKeys();
        int id = 0;
        if(generatedKeys.next()){
            id = generatedKeys.getInt(1);
        }
        return id;
    }

}
